package com.example.demo.service;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.demo.entity.SysUser;

@Service
public class ShouYeService {
	@Autowired
	private NewCar1Service carservice1;
	@Autowired
	private NewCar2Service carservice2;

	@Autowired
	private SysUserService sysUserService;
	@Autowired
	private CarsOrder2Service carorderService2;
	@Autowired
	private CarsOrderService carorderService1;
	@Autowired
	private SaleComputerService xiaoshouService;
	@Autowired
	private AfterSaleFrontWeiXiuComputerService weixiuService;
	@Autowired 
	private ErShouCheBuComPuterService ershoucheSerivce;
	
	/**
	 * @return 年收益一览（新车，维修，二手车）
	 * @throws ParseException 
	 */
	public Object nianShouYiYiLan() throws ParseException {
		DateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = new Date();// 获取当前时间
		Integer year = date.getYear() + 1900;
		Float xincheshouRu =(float) 0;
		Float xinchechengBen =(float) 0;
		Float xincheMaoLi =(float) 0;
		Float xincheMaoLiLv =(float) 0;
		Float ershoucheshouRu =(float) 0;
		Float ershouchechengBen =(float) 0;
		Float ershoucheMaoLi =(float) 0;
		Float ershoucheMaoLiLv =(float) 0;
		Float weixiuShouru=(float) 0;
		Float weixiuChengBen=(float) 0;
		Float weixiuMaoli=(float) 0;
		Float weixiuMaoliLv=(float) 0;
		List<Object> xinchelist=new ArrayList<Object>();
		List<Object> weixiulist=new ArrayList<Object>();
		List<Object> ershouchelist=new ArrayList<Object>();
		List<List<Object>> list=new ArrayList<List<Object>>();
		Date beginDate = dateformat.parse(year + "-01-01 00:00:00");
		Date endDate = dateformat.parse(year + "-12-31 00:00:00");
		List<SysUser> sysuserxiaoshou= sysUserService.findByDeptName("销售部");
		List<SysUser> sysusershouhou= sysUserService.findByDeptName("售后部");
		List<SysUser> sysuserershouche= sysUserService.findByDeptName("二手车部");
		for(SysUser user:sysuserxiaoshou) {
			 xincheshouRu += xiaoshouService.XiaoShouZongHeShouRu(user, beginDate, endDate);	
			 xinchechengBen += xiaoshouService.XiaoShouZongHeChengBen(user, beginDate, endDate);
			 xincheMaoLi += xiaoshouService.XiaoShouZongHeMaoLi(user, beginDate, endDate);
		}
		for(SysUser user:sysusershouhou) {
			weixiuMaoli+=weixiuService.weiXiuMaoLi(user, beginDate, endDate);
			weixiuChengBen+=weixiuService.weiXiuChengBen(user, beginDate, endDate);
			weixiuShouru += weixiuService.ShouHouWeiXiuShouRuHeJi(user, beginDate, endDate);
		}
		for(SysUser user:sysuserershouche) {
			ershoucheshouRu += ershoucheSerivce.XiaoShouZongHeShouRu(user, beginDate, endDate);	
			ershouchechengBen += ershoucheSerivce.XiaoShouZongHeChengBen(user, beginDate, endDate);
			ershoucheMaoLi += ershoucheSerivce.XiaoShouZongHeMaoLi(user, beginDate, endDate);
	
		}
		if(xincheshouRu!=0) {
			xincheMaoLiLv=xincheMaoLi/xincheshouRu;			
		}
		if(weixiuShouru!=0) {
			weixiuMaoliLv=weixiuMaoli/weixiuShouru;	
		}
		if(ershoucheshouRu!=0) {
			ershoucheMaoLiLv=ershoucheMaoLi/ershoucheshouRu;	
		}
		weixiulist.add(weixiuShouru);
		weixiulist.add(weixiuChengBen);
		weixiulist.add(weixiuMaoli);
		weixiulist.add(weixiuMaoliLv);
		xinchelist.add(xincheshouRu);
		xinchelist.add(xinchechengBen);
		xinchelist.add(xincheMaoLi);
		xinchelist.add(xincheMaoLiLv);
		ershouchelist.add(ershoucheshouRu);
		ershouchelist.add(ershouchechengBen);
		ershouchelist.add(ershoucheMaoLi);
		ershouchelist.add(ershoucheMaoLiLv);
		list.add(xinchelist);
		list.add(weixiulist);
		list.add(ershouchelist);
		return list;
	}
	/**
	 * @return 车辆销售综合收入一览
	 */
	
}
